﻿using System;
using System.Collections.Generic;
using System.Web;
namespace FTchina.Library
{
    /// <summary>
    ///MasterHelper 的摘要说明
    /// </summary>
    public class MasterHelper
    {
        public MasterHelper()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 判断用户是否登陆系统
        /// </summary>

        public static Boolean IsLogin
        {
            get { return (MasterID.Length != 0); }
        }

        /// <summary>
        /// 登录用户ID,每次登陆随机产生，MD5加密后保存
        /// </summary>
        public static string MasterID
        {
            get { return RequestHelper.GetCookie("master_id"); }
            set { RequestHelper.WriteCookie("master_id", value); }
        }


        /// <summary>
        /// 登陆用户名称ID
        /// </summary>
        public static string MasterName
        {
            get { return SecurityHelper.Decrypt(RequestHelper.GetCookie("master_name")); }
            set { RequestHelper.WriteCookie("master_name", SecurityHelper.Encrypt(value)); }
        }


        /// <summary>
        /// 登陆用户昵称
        /// </summary>
        public static string Nickname
        {
            get { return SecurityHelper.Decrypt(RequestHelper.GetCookie("master_nickname")); }
            set { RequestHelper.WriteCookie("master_nickname", SecurityHelper.Encrypt(value)); }
        }


        /// <summary>
        /// 用户权限
        /// </summary>
        public static string MasterPower
        {
            get { return SecurityHelper.Decrypt(RequestHelper.GetCookie("master_power")); }
            set { RequestHelper.WriteCookie("master_power", SecurityHelper.Encrypt(value)); }
        }
        /// <summary>
        /// 用户权限名称
        /// </summary>
        public static string MasterPowerName
        {
            get { return SecurityHelper.Decrypt(RequestHelper.GetCookie("master_powername")); }
            set { RequestHelper.WriteCookie("master_powername", SecurityHelper.Encrypt(value)); }
        }


        /// <summary>
        /// 登陆用户进行操作记录ID
        /// </summary>
        public static string Luruid
        {
            get { return SecurityHelper.Decrypt(RequestHelper.GetCookie("master_luruid")); }
            set { RequestHelper.WriteCookie("master_luruid", SecurityHelper.Encrypt(value)); }
        }



        /// <summary>
        /// 通过用户id获取用户名
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetUserNameById(string id)
        {

            return shujuku.GetValueByKey("master_name", "master", "link='" + id + "'");
        }


        /// <summary>
        /// 获取格式化用户id名称,如  13|魏宝辉
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetFormatUidName()
        {
            return Luruid + "|" + GetUserNameById(Luruid);
        }


        /// <summary>
        /// 设置用户登录IP
        /// </summary>
        private static String _LoginIP;
        public static String LoginIP
        {
            get { return _LoginIP; }
            set { _LoginIP = value; }
        }
    }

}
